import 'package:bigegg/global/user/xmm_account_manager.dart';
import 'package:bigegg/global/xmm_h5_url.dart';
import 'package:bigegg/page/user/setting/xmm_setting_page.dart';
import 'package:get/get.dart';

import '../../common/log/xmm_log.dart';
import '../../page/article/detail/xmm_article_detail_binding.dart';
import '../../page/article/detail/xmm_article_detail_page.dart';
import '../../page/article/publish/xmm_article_publish_binding.dart';
import '../../page/article/publish/xmm_article_publish_page.dart';
import '../../page/guide/xmm_guide_page.dart';
import '../../page/im/chat/xmm_chat_binding.dart';
import '../../page/im/chat/xmm_chat_page.dart';
import '../../page/login/xmm_login_binding.dart';
import '../../page/login/xmm_login_page.dart';
import '../../page/main/xmm_main_binding.dart';
import '../../page/main/xmm_main_page.dart';
import '../../page/shopping/xmm_shopping_coin_binding.dart';
import '../../page/shopping/xmm_shopping_coin_page.dart';
import '../../page/user/about/xmm_about_binding.dart';
import '../../page/user/about/xmm_about_page.dart';
import '../../page/user/edit/xmm_user_edit_binding.dart';
import '../../page/user/edit/xmm_user_edit_page.dart';
import '../../page/user/gift/xmm_my_gifts_binding.dart';
import '../../page/user/gift/xmm_my_gifts_page.dart';
import '../../page/user/person/xmm_user_person_binding.dart';
import '../../page/user/person/xmm_user_person_page.dart';
import '../../page/user/setting/xmm_setting_binding.dart';
import '../../page/webview/xmm_web_page.dart';

class XmmRoutes {
  //引导页
  static const String guidePage = '/guide';

  //登陆页
  static const String loginPage = '/login';

  //首页
  static const String mainPage = '/main';

  //webView
  static const String webView = '/webView';

  //个人主页
  static const String personPage = '/personPage';

  //作品详情页
  static const String articleDetailPage = '/articleDetailPage';

  //作品发布页
  static const String publishArticlePage = '/publishArticlePage';

  //聊天页
  static const String chatPage = '/chatPage';

  //购买金币页面
  static const String shoppingCoinPage = '/shoppingCoinPage';

  //用户编辑页面
  static const String userEditPage = '/userEditPage';

  //设置页面
  static const String settingPage = '/settingPage';

  //关于页面
  static const String aboutPage = '/aboutPage';

  //礼物页面
  static const String giftPage = '/giftPage';

  static final routePage = [
    GetPage(
      name: guidePage,
      page: () => const XmmGuidePage(),
    ),
    GetPage(
      name: loginPage,
      page: () => const XmmLoginPage(),
      binding: XmmLoginBinding(),
    ),
    GetPage(
      name: mainPage,
      page: () => const XmmMainPage(),
      binding: XmmMainBinding(),
    ),
    GetPage(
      name: webView,
      page: () => const XmmWebPage(),
    ),
    GetPage(
      name: personPage,
      page: () => const XmmUserPersonPage(),
      binding: XmmUserPersonBinding(),
    ),
    GetPage(
      name: articleDetailPage,
      page: () => const XmmArticleDetailPage(),
      binding: XmmArticleDetailBinding(),
    ),
    GetPage(
      name: publishArticlePage,
      page: () => const XmmArticlePublishPage(),
      binding: XmmArticlePublishBinding(),
    ),
    GetPage(
      name: chatPage,
      page: () => const XmmChatPage(),
      binding: XmmChatBinding(),
    ),
    GetPage(
      name: shoppingCoinPage,
      page: () => const XmmShoppingCoinPage(),
      binding: XmmShoppingCoinBinding(),
    ),
    GetPage(
      name: userEditPage,
      page: () => const XmmUserEditPage(),
      binding: XmmUserEditBinding(),
    ),
    GetPage(
      name: giftPage,
      page: () => const XmmMyGiftsPage(),
      binding: XmmMyGiftsBinding(),
    ),
    GetPage(
      name: aboutPage,
      page: () => const XmmAboutPage(),
      binding: XmmAboutBinding(),
    ),
    GetPage(
      name: settingPage,
      page: () => const XmmSettingPage(),
      binding: XmmSettingBinding(),
    ),
  ];

  static void routeWebPage(String url) {
    if(url == XmmH5Url.privacyPolicy){
      XmmLogManger().putLog(XmmLogType.clickEvent, {'page': XmmLogPages.pagePrivacy});
    } else if(url == XmmH5Url.userAgreement){
      XmmLogManger().putLog(XmmLogType.clickEvent, {'page': XmmLogPages.pageTerms});
    }
    Get.toNamed(webView, arguments: url);
  }

  static void routeCsPage() {
    XmmLogManger().putLog(XmmLogType.clickEvent, {'page': XmmLogPages.pageCustomer});
    Get.toNamed(
      chatPage,
      arguments: XmmAccountManager.instance.strategy?.userServiceAccountId ?? "",
    );
  }

  static void routePersonPage(String userId) {
    if(userId == XmmAccountManager.instance.user.userId){
      return;
    }
    Get.toNamed(personPage, arguments: userId);
  }

  static backMain() {
    Get.until((route) => route.settings.name == mainPage);
  }
}
